package com.lagou.study.filter;

import com.lagou.study.Constant;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long startTime = System.currentTimeMillis();
        try {
            // 执行方法
            return  invoker.invoke(invocation);
        } finally {
            Constant.methodName.set(invocation.getMethodName());
            Constant.time.set(System.currentTimeMillis()-startTime);
            //RpcContext.getContext().setAttachment(invocation.getMethodName(),System.currentTimeMillis()-startTime);
            //System.out.println(invocation.getMethodName()+" invoke time:"+(System.currentTimeMillis()-startTime) + "毫秒");
        }

    }
}
